// 'use client';

import { getCookie } from "cookies-next";

export const fallbackLng = "zh_CN";
export const languages = [fallbackLng, "zh_CN", "zh", "en_US", "en"];
export const defaultNS = "common";
export const cookieName = "i18next";

// 语言代码映射：将简化的语言代码映射到完整的语言代码
const languageCodeMap: Record<string, string> = {
  zh: "zh_CN",
  en: "en_US",
  zh_CN: "zh_CN",
  en_US: "en_US",
};

// 语言代码到文件名的映射
const languageToFileNameMap: Record<string, string> = {
  zh: "zh_CN",
  en: "en_US",
  zh_CN: "zh_CN",
  en_US: "en_US",
};

// 标准化语言代码：将任何语言代码转换为标准格式
export function normalizeLanguageCode(lang: string): string {
  return languageCodeMap[lang] || fallbackLng;
}

// 获取语言文件名
export function getLanguageFileName(lang: string): string {
  return languageToFileNameMap[lang] || "zh_CN";
}

export function getOptions(lng = fallbackLng, ns = defaultNS) {
  const defaultLang = getCookie("i18next") || "zh_CN";
  return {
    // debug: true,
    supportedLngs: languages,
    fallbackLng: fallbackLng,
    lng: fallbackLng,
    fallbackNS: defaultNS,
    defaultNS,
    ns,
  };
}
